#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL par[6][3]{ {0,1,2},{0,2,1},{1,2,0},{1,0,2},{2,0,1},{2,1,0} };
LL pre[maxn][6];
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL n,m;cin>>n>>m;
    string s;cin>>s;
   	for(LL i=0;i<n;i++){
        for(LL j=0;j<6;j++){
            pre[i+1][j]=pre[i][j]+( (s[i]-'a')!=par[j][i%3] );
        }
   	}
   	while(m--){
        LL l,r;cin>>l>>r;
        LL ans=1e18;
        for(LL j=0;j<6;j++){
            ans=min(ans,pre[r][j]-pre[l-1][j]);
        }
        cout<<ans<<"\n";
   	}
   	return 0;
}
